<template>
  <div>
    <el-row>
        <el-col :span="10" :offset="7">
            请输入采购单编号：<el-input v-model="inStockDTO.procurementId"></el-input>
            <el-button type="success" @click="getPurchaseMsg">查看商品信息</el-button>
        </el-col>
    </el-row>
    <el-row>
        <el-col>
            <template>
                <el-select v-model="inStockDTO.type" placeholder="请选择入库单类型">
                    <el-option label="采购入库" value="1"></el-option>
                    <el-option label="代存入库" value="2"></el-option>
                </el-select>
                <el-select v-model="inStockDTO.depotId" placeholder="请选择仓库">
                    <el-option v-for="item in depotList" :key="item.id" :label="item.account" :value="item.id"></el-option>
                </el-select>               
                <el-button type="primary" @click="addForm">立即添加</el-button>
                <el-button @click="this.goDetailin">取消</el-button>
            </template>
        </el-col>
    </el-row>
    <el-row>
        <el-col>
            <template>
                <el-table
                    :data="goodsList"
                    tooltip-effect="dark"
                    style="width: 100%">
                    <el-table-column type="index" :index="indexMethod">
                    </el-table-column>
                    <el-table-column prop="goodsName" label="商品名"> </el-table-column>
                    <el-table-column prop="meteriType" label="材质"> </el-table-column>
                    <el-table-column prop="purity" label="品质"> </el-table-column>
                    <el-table-column prop="quantity" label="数量"> </el-table-column>
                    <el-table-column prop="weight" label="重量"> </el-table-column>
                    <el-table-column prop="unitPrice" label="价格/克"> </el-table-column>
                </el-table>
            </template>
        </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
    data() {
      return {
        inStockDTO:{
            procurementId: null,
            formMaker:"",
            type: null,
            customer: null,
            depotId: null,
            items: [],
        },
        goodsList: [],
        depotList: [],
          
      };
    },
    mounted: function(){
        this.inStockDTO.formMaker = window.localStorage.getItem("account");
        this.$axios.get("/depot/listForInStock").then(result => {
            this.depotList = result.data.data;
        });
    },
    methods: {
        getPurchaseMsg(){
            this.$axios.get("/purchase/buyPurchase/findAllPurchase/" + this.inStockDTO.procurementId).then(res => {
                console.log(res.data);
                var goodsList2 = res.data.data[0].goods
                this.goodsList = res.data.data[0].goods
                this.inStockDTO.customer = res.data.data[0].supplierName
 
                var arr=[]
                for (let i = 0; i< goodsList2.length; i++) {
                    arr.push({itemCode:goodsList2[i].goodsNumber,num:goodsList2[i].quantity})
                           
                    }
                    this.inStockDTO.items = arr;    
            });
        },
        indexMethod(index) {
            return index + 1;
        },
        addForm(){
            console.log(this.inStockDTO);
            this.$axios.post("/inStock/insert",this.inStockDTO).then(res => {
                this.goDetailin();
            })
        },
        goDetailin(){
            this.$router.push("/detailin");
        },
    }
}
</script>

<style scoped>
</style>